﻿@model LCTMoodle.Models.ViewModels.CauHoiViewModel

@{
    Layout = "~/Views/Shared/_Khung.cshtml";

    ViewBag.SiteMap = new string[] 
    {
        "Trang chủ", "/TrangChu",
        "Hỏi đáp", "/HoiDap",
        Model.tieuDe, "/HoiDap/CauHoi/" + Model.ma
    };

    TempData["TimKiem"] = "HoiDap";

    LCTMoodle.Models.ViewModels.NguoiDungViewModel nguoiDung = HttpContext.Current.Session["nguoiDung"] == null ? null : HttpContext.Current.Session["nguoiDung"] as LCTMoodle.Models.ViewModels.NguoiDungViewModel;

    bool coTheXoaCauHoi, coTheDanhGia;

    if (nguoiDung != null)
    {
        coTheXoaCauHoi = nguoiDung.loaiNguoidung == "QuanLy" || nguoiDung.ma == Model.nguoiTao.ma;
        coTheDanhGia = Model.nguoiTao.ma != nguoiDung.ma;
    }
    else
    {
        coTheXoaCauHoi = false;
        coTheDanhGia = false;
    }    
}

<link href="~/Content/css/HoiDap/CauHoi.css" rel="stylesheet" type="text/css" />

<link href="~/Content/froala/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<link href="~/Content/froala/css/froala_editor.min.css" rel="stylesheet" type="text/css" />
<link href="~/Content/froala/css/themes/gray.min.css" rel="stylesheet" type="text/css" />

@section RightAside
{
    <section class="section">
        <article class="title">
            <i class="icon"></i>
            <h2 class="text">Chức năng</h2>
        </article>
        <ul class="box function-box">
            <li>
                <a href="/HoiDap/DatCauHoi">
                    Tạo câu hỏi
                </a>
            </li>
        </ul>
    </section>
}

<section class="phan-cau-hoi">
    <section class="action-button">
        <i class="pe-7s-config"></i>
        <ul>
            @if (coTheXoaCauHoi)
            {
                <li>
                    <a href="/HoiDap/XoaCauHoi/@Model.ma" onclick="return confirm('Bạn có chắc là muốn xóa?')">
                        Xóa
                    </a>
                </li>
            }
        </ul>
    </section>
    <h2 class="tieu-de" data-time="@Model.thoiDiemTao">
        @Model.tieuDe
    </h2>
    <section class="noi-dung">
        @Html.Raw(Model.noiDung)
    </section>
    <section class="thong-tin">
        @if (coTheDanhGia)
        {
            <section class="danh-gia co">
                <button class="tang 
                    @if (Model.chuoiMaNguoiDungDanhGiaTot.IndexOf("|" + nguoiDung.ma + "|") != -1)
                    {
                        @:da
                    }
                    "></button>
                <div class="diem">@Model.danhGia</div>
                <button class="giam 
                    @if (Model.chuoiMaNguoiDungDanhGiaXau.IndexOf("|" + nguoiDung.ma + "|") != -1)
                    {
                        @:da
                    }"></button>
            </section>        
        }
        else
        {
            <section class="danh-gia khong">
                <button class="tang" disabled="disabled"></button>
                <div class="diem">@Model.danhGia</div>
                <button class="giam" disabled="disabled"></button>
            </section>        
        }
        <section class="thong-tin-bai 
            @switch (Model.trangThai)
            {
                case 1:
                    @:da-tra-loi
                    break;
                default:
                    @:chua-tra-loi
                    break;
            }">
            <section class="nguoi-dang">
                @Model.nguoiTao.hoTen
            </section>
            <section class="thong-tin-them">
                <span>
                    @Model.luotXem
                </span>
                <span>
                    @Model.luotTraLoi
                </span>
            </section>
        </section>
        <ul class="tu-khoa">
            @foreach (LCTMoodle.Models.ViewModels.TuKhoaViewModel tuKhoa in @Model.danhSachTuKhoa)
            {
                <li>
                    <a href="#">
                        @tuKhoa.tuKhoa
                    </a>
                </li>
            }
        </ul>
    </section>
</section>
<section class="phan-tra-loi">
    <ul id="danh-sach-tra-loi">
    </ul>
    <form id="khung-soan-tra-loi" class="khung-soan-tra-loi">
        <input name="MaCauHoi" type="hidden" value="@Model.ma" />
        <textarea id="viet-bai" name="NoiDung" class="editor" placeholder="Viết bài..."></textarea>
        <section class="post-button-container">
            <i class="pe-7s-check"></i>
            <input type="submit" value="Đăng" class="post-button" />
        </section>            
    </form>
</section>

<script src="~/Content/froala/js/froala_editor.min.js"></script>
<script src="~/Content/froala/js/plugins/colors.min.js"></script>
<script src="~/Content/froala/js/plugins/font_size.min.js"></script>
<script src="~/Content/froala/js/plugins/lists.min.js"></script>

<script src="~/Content/script/HoiDap/CauHoi.js"></script>

<script>
    maCauHoi = '@Model.ma';

    $('#viet-bai').editable({
        inlineMode: false,
        buttons: ['bold', 'italic', 'underline', 'fontSize', 'color', 'align', 'formatBlock', 'insertOrderedList', 'insertUnorderedList', 'createLink', 'insertImage'],
        zIndex: 3,
        theme: 'gray',
        blockTags: ['p', 'pre', 'blockquote']
    });
</script>
